<?php
require_once (dirname(__FILE__)."/../config/config.php");

if($_REQUEST['method']=='registerSendId')
{
	$message=registerSendId();
	echo json_encode($message);
}
if($_REQUEST['method']=='unregisterSendId')
{
	$message=unregisterSendId();
	echo json_encode($message);
}
//注册设备
function registerSendId()
{
	$userid=$_REQUEST['userid'];
	$imei=$_REQUEST['imei'];
	$platform=$_REQUEST['platform'];
	$send_id=$_REQUEST['send_id'];
	$app_id=$_REQUEST['app_id'];
	if($userid>0)
	{
	$sqlupdate="update zy_appuser set userid=$userid where send_id='$send_id' and imei='$imei' and platform=$platform and app_id=$app_id";
	if(mysql_query($sqlupdate))
	{
			$message= array (
			'message' => '0598'//修改成功
		);	
	}else{
			$message= array (
			'message' => '0502'//修改失败
		);	
	}
	return $message;
	}else{
		$userid=0;
		$sqlselect="select * from zy_appuser where send_id='$send_id' and imei='$imei' and app_id=$app_id";
		$result=mysql_query($sqlselect);
		if($row=mysql_fetch_array($result))
		{
			$message= array (
			'message' => '0597'//已存在
		);	
		return $message;
		}else{
		$sqlinsert="insert into zy_appuser(userid,send_id,imei,platform,app_id) values($userid,'$send_id','$imei',$platform,$app_id)";
		if(mysql_query($sqlinsert))
		{
			$message= array (
			'message' => '0599'//注册成功
		);	
		}else{
				$message= array (
			'message' => '0501'//注册失败
		);
		}
		return $message;
		}	
	}
}
//注销设备
function unregisterSendId()
{
	//$userid=$_REQUEST['userid'];
	$imei=$_REQUEST['imei'];
	$app_id=$_REQUEST['app_id'];
	if($_REQUEST['userid']==null)
	{
		$userid=0;
	}else{
		$userid=$_REQUEST['userid'];
	}
	$sqldelete="delete from zy_appuser where userid=$userid and imei='$imei' and app_id=$app_id";
	if(mysql_query($sqldelete))
	{
				$message= array (
			'message' => '0596'//注销成功
		);
	}else{
				$message= array (
			'message' => '0503'//注销失败
		);
	}
	return $message;
}
?>
